package com.koron.device.mapper;

import com.koron.device.bean.EquipmentLocation;
import com.koron.device.bean.EquipmentLocationQuery;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;
import java.util.Map;

@Mapper
public interface EquipmentLocationMapper {

    List<EquipmentLocation> getList(EquipmentLocationQuery equipmentLocationQuery);

    //检查同父级下位置重名
    List<EquipmentLocation> queryByNameAndParentIdAndDeleteFlag(@Param("name") String name, @Param("parentId") String parentId, @Param("deleteFlag") Integer deleteFlag);

    Integer getMaxLevelCodeByLevelPath(@Param("levelPath") String levelPath);

    /**
     * 获取所有有经纬度，且处于启用状态的定位
     *
     * @return
     */
    List<EquipmentLocation> getRangeLocation(EquipmentLocationQuery equipmentLocationQuery);

    String getLevelPathById(@Param("id") String parentId);

    void replaceLevelPath(List<Map<String, String>> list);

    List<EquipmentLocation> getBrotherNode(@Param("parentId") String parentId, @Param("levelCode") int levelCode);

    void insert(EquipmentLocation equipmentLocation);

    Integer update(EquipmentLocation equipmentLocation);

    EquipmentLocation getById(@Param("id") String id);

    List<EquipmentLocation> getBatchByIds(@Param("ids") List<String> ids);

    void updateChildrenParentId(@Param("originalParentId") String originalParentId, @Param("targetId") String targetId);

    EquipmentLocation getByCode(@Param("code") String code);

    EquipmentLocation getByNameAndParentId(@Param("name") String name, @Param("parentId") String parentId);

    Integer getCurrentParentMaxSort(@Param("parentId") String parentId);

    EquipmentLocation getByEquipId(@Param("equipId") String equipId);

    void insertBak(EquipmentLocation equipmentLocation);

    void updateSortForward(@Param("sort") Integer sort, @Param("end") Integer end, @Param("parentId") String parentId);

    void updateSortBackward(@Param("start") Integer start, @Param("sort") Integer sort, @Param("parentId") String parentId);

    List<EquipmentLocation> getListBak();

    String getParentIdById(@Param("orgId") String orgId);

    void updateBak(EquipmentLocation equipmentLocation);

    Integer getSortById(@Param("id") String id);

    Integer getMinLevelByOrgId(@Param("orgId") String orgId);

    Integer getMinLevelCodeByOrgIdAndLevel(@Param("orgId") String orgId, @Param("level") Integer level);

    String getLevelPathByLevelAndLevelCode(@Param("level") Integer level, @Param("levelCode") Integer levelCode);

    String getIdByLevelAndLevelCode(@Param("level") Integer level, @Param("levelCode") Integer levelCode);

    EquipmentLocation getLeftUpperLocation(@Param("orgId") String orgId);

    List<EquipmentLocation> queryByFullPathCodeLike(@Param("likeFullPathCode") String likeFullPathCode);

    List<EquipmentLocation> queryByDeleteFlag(@Param("deleteFlag") Integer deleteFlag);

    // 批量插入 用于导入
    int batchInsert(@Param("list") List<EquipmentLocation> list);

    List<EquipmentLocation> queryAll();

    // 更新位置父级名称
    int updateParentName();

    List<EquipmentLocation> selectByNameList(@Param("list") List<String> list);
}
